package com.dhms.uikit.deviceCategory

import android.annotation.SuppressLint
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip

@SuppressLint("NotifyDataSetChanged")
@BindingAdapter("deviceCategoryListData")
fun bindDeviceCategoryList(recyclerView: RecyclerView, data: MutableList<DeviceCategoryItem>?) {
    val adapter = recyclerView.adapter ?: return
    adapter as DeviceCategoryListAdapter
    adapter.submitList(data)
    adapter.notifyDataSetChanged()
}

@SuppressLint("NotifyDataSetChanged")
@BindingAdapter("deviceSubCategoryListData")
fun bindDeviceSubCategoryList(
    recyclerView: RecyclerView,
    data: MutableList<DeviceSubCategoryItem>?
) {
    val adapter = recyclerView.adapter ?: return
    adapter as DeviceSubCategoryListAdapter
    adapter.submitList(data)
    adapter.notifyDataSetChanged()
}

@BindingAdapter("stateSelected")
fun bindingStateSelected(chip: Chip, item: DeviceCategoryItem) {
    chip.isChecked = item.checkable
}